package com.gt.web.srv.web.api.wx;

import com.gt.web.srv.service.wx.WechatPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/api/wechat/pay")
public class WechatPayController {

    @Autowired
    private WechatPayService wechatPayService;

    /**
     * JSAPI支付
     */
    @PostMapping("/jsapi")
    public String jsapiPay(@RequestParam String openId,
                           @RequestParam String orderNo,
                           @RequestParam Long amount,
                           @RequestParam String description) {
        return wechatPayService.jsapiPrepay(openId, orderNo, amount, description);
    }

    /**
     * 查询订单
     */
    @GetMapping("/query")
    public Object queryOrder(@RequestParam String orderNo) {
        return wechatPayService.queryOrder(orderNo);
    }

    /**
     * 关闭订单
     */
    @PostMapping("/close")
    public void closeOrder(@RequestParam String orderNo) {
        wechatPayService.closeOrder(orderNo);
    }

    /**
     * 申请退款
     */
    @PostMapping("/refund")
    public Object refund(@RequestParam String orderNo,
                         @RequestParam String refundNo,
                         @RequestParam Long totalAmount,
                         @RequestParam Long refundAmount,
                         @RequestParam String reason) {
        return wechatPayService.refund(orderNo, refundNo, totalAmount, refundAmount, reason);
    }

    /**
     * 查询退款
     */
    @GetMapping("/refund/query")
    public Object queryRefund(@RequestParam String refundNo) {
        return wechatPayService.queryRefund(refundNo);
    }
}